/* Copyright (c) 2007, Jan Flora <janflora@diku.dk>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 *  - Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *  - Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  - Neither the name of the University of Copenhagen nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 * SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
  @author Jan Flora <janflora@diku.dk>
*/

//includes mcuToRadioPorts;
#include <macConstants.h>;

configuration Ieee802154C
{
	provides
	{
		interface StdControl;

		// interfaces for handling 802.15.4 messaging
		// MCPS
		interface IeeeIndication<Mcps_DataIndication> as McpsIndicationData;
		interface IeeeRequestConfirm<Mcps_DataRequestConfirm> as McpsRequestConfirmData;
		interface IeeeRequestConfirm<Mcps_PurgeRequestConfirm> as McpsRequestConfirmPurge;
		// MLME
		
		interface IeeeRequestConfirm<Mlme_AssociateRequestConfirm> as MlmeRequestConfirmAssociate;
		interface IeeeIndication<Mlme_DisassociateIndication> as MlmeIndicationDisassociate;
		interface IeeeRequestConfirm<Mlme_DisassociateRequestConfirm> as MlmeRequestConfirmDisassociate;						
		interface IeeeSyncRequestConfirm<Mlme_GetRequestConfirm> as MlmeRequestConfirmGet;
		interface IeeeRequestConfirm<Mlme_PollRequestConfirm> as MlmeRequestConfirmPoll;
		interface IeeeRequestConfirm<Mlme_ResetRequestConfirm> as MlmeRequestConfirmReset;
		interface IeeeRequestConfirm<Mlme_RxEnableRequestConfirm> as MlmeRequestConfirmRxEnable;
		interface IeeeRequestConfirm<Mlme_ScanRequestConfirm> as MlmeRequestConfirmScan;
		interface IeeeSyncRequestConfirm<Mlme_SetRequestConfirm> as MlmeRequestConfirmSet;

		#ifdef COORDINATOR_SUPPORT
			interface IeeeIndicationResponse<Mlme_AssociateIndicationResponse> as MlmeIndicationResponseAssociate;
			interface IeeeIndication<Mlme_CommStatusIndication> as MlmeIndicationCommStatus;
			interface IeeeIndicationResponse<Mlme_OrphanIndicationResponse> as MlmeIndicationResponseOrphan;
			interface IeeeRequestConfirm<Mlme_StartRequestConfirm> as MlmeRequestConfirmStart;
		#endif

		#ifdef BEACON_SUPPORT
			interface IeeeIndication<Mlme_BeaconNotifyIndication> as MlmeIndicationBeaconNotify;
			interface IeeeIndication<Mlme_SyncLossIndication> as MlmeIndicationSyncLoss;
			interface IeeeRequest<Mlme_SyncRequest> as MlmeRequestSync;
			#ifdef GTS_SUPPORT
				interface IeeeIndication<Mlme_GtsIndication> as MlmeIndicationGts;		
				interface IeeeRequestConfirm<Mlme_GtsRequestConfirm> as MlmeRequestConfirmGts;
			#endif
		#endif

		// interfaces for handling 802.15.4 primitive types		
		interface IeeeMacSdu as IeeeSdu;
		interface IeeeMacPibAttribute as IeeePibAttribute;
		interface IeeePanDescriptor;
		interface IeeeAddress;
		
		interface McpsDataIndication;
		interface McpsDataRequestConfirm;
		interface McpsPurgeRequestConfirm;

		interface MlmeAssociateRequestConfirm;
		interface MlmeDisassociateRequestConfirm;
		interface MlmeDisassociateIndication;
		interface MlmeGetRequestConfirm;
		interface MlmePollRequestConfirm;
		interface MlmeResetRequestConfirm;
		interface MlmeRxEnableRequestConfirm;
		interface MlmeScanRequestConfirm;
		interface MlmeSetRequestConfirm;
		
		#ifdef COORDINATOR_SUPPORT
			interface MlmeAssociateIndicationResponse;
			interface MlmeCommStatusIndication;
			interface MlmeOrphanIndicationResponse;
			interface MlmeStartRequestConfirm;
		#endif
		
		#ifdef BEACON_SUPPORT
			interface MlmeBeaconNotifyIndication;
			interface MlmeSyncRequest;
			interface MlmeSyncLossIndication;
			#ifdef GTS_SUPPORT
				interface MlmeGtsRequestConfirm;
				interface MlmeGtsIndication;
			#endif
		#endif
	}
	uses
	{
		interface Debug;
	}
}

implementation
{
	components mc13192PhyDriverC,
	           HPLSPIM as mcuSPI,
	           Ieee802154MacC,
	           HPLTimer2M,
	           AsyncAlarmC,
	           FastLfsrM,
	           SimpleBufferManM,
	           FIFOQueueM;

	// Wire standard control
	StdControl = mcuSPI.StdControl;
	StdControl = HPLTimer2M.StdControl;
	StdControl = mc13192PhyDriverC.StdControl;
	StdControl = AsyncAlarmC.StdControl;
	StdControl = SimpleBufferManM.StdControl;
	StdControl = Ieee802154MacC.StdControl;

	// Connect debug.
	Ieee802154MacC.Debug = Debug;
	mc13192PhyDriverC.Debug = Debug;
	FIFOQueueM.Debug = Debug;
	SimpleBufferManM.Debug = Debug;
	AsyncAlarmC.Debug = Debug;
	
	// Connect Phy.
	mc13192PhyDriverC.SPI -> mcuSPI.SPI;
	mc13192PhyDriverC.MCUTime -> AsyncAlarmC.LocalTime;

	Ieee802154MacC.PhyReceive -> mc13192PhyDriverC.PhyReceive;
	Ieee802154MacC.PhyTransmit -> mc13192PhyDriverC.PhyTransmit;
	Ieee802154MacC.PhyEnergyDetect -> mc13192PhyDriverC.PhyEnergyDetect;
	Ieee802154MacC.PhyAttributes -> mc13192PhyDriverC.PhyAttributes;
	Ieee802154MacC.PhyControl -> mc13192PhyDriverC.PhyControl;
	Ieee802154MacC.PhyReset -> mc13192PhyDriverC.PhyReset;

	// Wire alarms
	Ieee802154MacC.ScanAlarm -> AsyncAlarmC.Alarm[unique("AsyncAlarm")];
	Ieee802154MacC.EdAlarm -> AsyncAlarmC.Alarm[unique("AsyncAlarm")];
	Ieee802154MacC.RxEnableAlarm -> AsyncAlarmC.Alarm[unique("AsyncAlarm")];
	Ieee802154MacC.TimeoutAlarm1 -> AsyncAlarmC.Alarm[unique("AsyncAlarm")];
	Ieee802154MacC.TimeoutAlarm2 -> AsyncAlarmC.Alarm[unique("AsyncAlarm")];
	
	#ifdef BEACON_SUPPORT
		Ieee802154MacC.TrackAlarm -> AsyncAlarmC.Alarm[unique("AsyncAlarm")];
		#ifdef COORDINATOR_SUPPORT
			Ieee802154MacC.BeaconAlarm -> AsyncAlarmC.Alarm[unique("AsyncAlarm")];
			#ifdef GTS_SUPPORT
				Ieee802154MacC.GeneratorCfpAlarm -> AsyncAlarmC.Alarm[unique("AsyncAlarm")];
			#endif
		#endif
		#ifdef GTS_SUPPORT
			Ieee802154MacC.TrackerCfpAlarm -> AsyncAlarmC.Alarm[unique("AsyncAlarm")];
			Ieee802154MacC.CfpAlarm -> AsyncAlarmC.Alarm[unique("AsyncAlarm")];
			Ieee802154MacC.CfpAlarm2 -> AsyncAlarmC.Alarm[unique("AsyncAlarm")];
		#endif
	#endif
	
	Ieee802154MacC.LocalTime -> AsyncAlarmC.LocalTime;
 	
 	// Wire random generator
 	Ieee802154MacC.Random -> FastLfsrM.Random;
 	
 	// Wire buffer manager and queue
 	SimpleBufferManM.Queue -> FIFOQueueM.FIFOQueue;
 	Ieee802154MacC.FIFOQueue -> FIFOQueueM.FIFOQueue;
 	Ieee802154MacC.BufferMng -> SimpleBufferManM.BufferMng;
 	

	// messaging wiring
	// MCPS
	McpsIndicationData = Ieee802154MacC.McpsIndicationData;
	McpsRequestConfirmData = Ieee802154MacC.McpsRequestConfirmData;
	McpsRequestConfirmPurge = Ieee802154MacC.McpsRequestConfirmPurge;
	
	McpsDataIndication = Ieee802154MacC;
	McpsDataRequestConfirm = Ieee802154MacC;
	McpsPurgeRequestConfirm = Ieee802154MacC;
	
	//MLME
	MlmeRequestConfirmAssociate = Ieee802154MacC.MlmeRequestConfirmAssociate;
	MlmeIndicationDisassociate = Ieee802154MacC.MlmeIndicationDisassociate;
	MlmeRequestConfirmDisassociate = Ieee802154MacC.MlmeRequestConfirmDisassociate;
	MlmeRequestConfirmGet = Ieee802154MacC.MlmeRequestConfirmGet;
	MlmeRequestConfirmPoll = Ieee802154MacC.MlmeRequestConfirmPoll;
	MlmeRequestConfirmReset = Ieee802154MacC.MlmeRequestConfirmReset;
	MlmeRequestConfirmRxEnable = Ieee802154MacC.MlmeRequestConfirmRxEnable;
	MlmeRequestConfirmScan = Ieee802154MacC.MlmeRequestConfirmScan;
	MlmeRequestConfirmSet = Ieee802154MacC.MlmeRequestConfirmSet;
	
	#ifdef COORDINATOR_SUPPORT
		MlmeIndicationResponseAssociate = Ieee802154MacC.MlmeIndicationResponseAssociate;
		MlmeIndicationCommStatus = Ieee802154MacC.MlmeIndicationCommStatus;
		MlmeIndicationResponseOrphan = Ieee802154MacC.MlmeIndicationResponseOrphan;
		MlmeRequestConfirmStart = Ieee802154MacC.MlmeRequestConfirmStart;
	#endif
	
	#ifdef BEACON_SUPPORT
		MlmeIndicationBeaconNotify = Ieee802154MacC.MlmeIndicationBeaconNotify;
		MlmeIndicationSyncLoss = Ieee802154MacC.MlmeIndicationSyncLoss;
		MlmeRequestSync = Ieee802154MacC.MlmeRequestSync;
		#ifdef GTS_SUPPORT
			MlmeIndicationGts = Ieee802154MacC.MlmeIndicationGts;
			MlmeRequestConfirmGts = Ieee802154MacC.MlmeRequestConfirmGts;
		#endif
	#endif
	
	// primitive handling wiring
	IeeePibAttribute = Ieee802154MacC;
	IeeePanDescriptor = Ieee802154MacC;
	IeeeSdu = Ieee802154MacC;
	IeeeAddress = Ieee802154MacC;

	MlmeAssociateRequestConfirm = Ieee802154MacC;
	MlmeDisassociateRequestConfirm = Ieee802154MacC;
	MlmeDisassociateIndication = Ieee802154MacC;
	MlmeGetRequestConfirm = Ieee802154MacC;
	MlmePollRequestConfirm = Ieee802154MacC;
	MlmeResetRequestConfirm = Ieee802154MacC;
	MlmeRxEnableRequestConfirm = Ieee802154MacC;
	MlmeScanRequestConfirm = Ieee802154MacC;
	MlmeSetRequestConfirm = Ieee802154MacC;
	
	#ifdef COORDINATOR_SUPPORT
		MlmeAssociateIndicationResponse = Ieee802154MacC;
		MlmeCommStatusIndication = Ieee802154MacC;
		MlmeOrphanIndicationResponse = Ieee802154MacC;
		MlmeStartRequestConfirm = Ieee802154MacC;
	#endif
	
	#ifdef BEACON_SUPPORT
		MlmeBeaconNotifyIndication = Ieee802154MacC;
		MlmeSyncRequest = Ieee802154MacC;
		MlmeSyncLossIndication = Ieee802154MacC;
		#ifdef GTS_SUPPORT
			MlmeGtsRequestConfirm = Ieee802154MacC;
			MlmeGtsIndication = Ieee802154MacC;
		#endif
	#endif
}